var id=location.search;
id=id.split('?')[1];
var already;
var nosub;
if (islogin()) {
    $.post({
        url:'../../requests/teacher/select_submit.php',
        data:{'id':id},
        async:false,
        success:function (data) {
            $('#already_sum').text(data.already.length);
            $('#nosub_sum').text(data.nosub.length);
            $('#all_sum').text(data.all.length);
            already=data.already;
            nosub=data.nosub;
            append_already(already);
            append_nosub(nosub);
        }
    });
    $('#select_status').change(function () {
        if ($(this).val() == 'all') {
            $('.sub_box ul').empty();
            append_already(already);
            append_nosub(nosub);
        }
        else if ($(this).val() == 'already') {
            $('.sub_box ul').empty();
            append_already(already);
        }
        else if($(this).val()=='nosub'){
            $('.sub_box ul').empty();
            append_nosub(nosub);
        }
    });
    $('.sub_box ul').on('click','.btn_grade',function () {
             var that=this;
            var id=$(this).attr('id').split('_')[1];
            $$.prompt('请输入评分',function (value) {
                if (isNaN(value)) {
                    $$.alert('输入的不是数字');
                }
                else {
                    $.post({
                        url:'../../requests/teacher/grade.php',
                        data:{'id':id,'score':value},
                        success:function (data) {
                            if (data == 1) {
                                $$.alert('评分成功',function () {
                                    $(that).parent().find('.score').text(value);
                                });
                            }
                            else $$.alert('评分失败！');
                        }
                    });
                }
            });
    });

}
else window.location.href='../../index.html';

function append_already(already) {
    for (var i = 0; i < already.length; i++) {
        var dom="<li class='item-content'>" +
            "<div class='item-inner'>" +
            "<div class='item-title'>" +
            "<span>"+already[i].name+"</span>"+
            "<span>"+already[i].student+"</span>"+
            "</div>"+
            "<div class='item-after'>" +
            "<span class='score'>"+already[i].score+"</span>&nbsp;"+
            "<button class='button btn_grade' id='id_"+already[i].Id+"'>评分</button>"+
            "<a class='d-homework' href='../../"+already[i].attach+"'>下载<span class='icon icon-download'></span></a>"+
            "</div>"+
            "</div>"+
            "</li>";
        $('.sub_box ul').append(dom);
    }
}

function append_nosub(nosub) {
    for (var i = 0; i < nosub.length; i++) {
        var dom="<li class='item-content'>" +
            "<div class='item-inner'>" +
            "<div class='item-title'>" +
            "<span>"+nosub[i].name+"</span>"+
            "<span>"+nosub[i].num+"</span>"+
            "</div>"+
            "<div class='item-after'>未提交" +
            "</div>"+
            "</div>"+
            "</li>";
        $('.sub_box ul').append(dom);
    }
}